
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include "debug.h"
#include "scanner.h"
#include "token.h"
#include "hash.h"
#include "expr.h"

#include "alloc.h"


int main(){
      AllocTable = NULL;
      AllocInit();
      
      bInWhere = true;
      
      
//     DOMYSLET !!!!
//     ptrht = (tHTable*) malloc ( sizeof(tHTable) );
//     _debug("%d", *ptrht);
//     free(ptrht);
//     _debug("%d", *ptrht);
//     return 0;
    
    //testy pro instruction list
    /*
    TIList InstructionList; */
    InitIList(&InstructionList);

    
//     char * x = "\"BLABLA\"";
//     AddInstruction (&InstructionList, IS_WRITE, x, x, x);
//     AddInstruction (&InstructionList, IS_WRITE, x, x, x);
//     AddInstruction (&InstructionList, IS_WRITE, x, x, x);
//     AddInstruction (&InstructionList, IS_WRITE, x, x, x);
//     AddInstruction (&InstructionList, IS_WRITE, "NECO", x, x);
//     _debug_instructions(&InstructionList);
//     
//     return 0;
    
    
    system("clear");
    InputFile = fopen ("test.input","rt");
    if (NULL== InputFile)
    {
      _error("neotevru %s\n","test.input");
      exit (1);
    }
    ptrht = (tHTable*) malloc ( sizeof(tHTable) );
    ptrlocalht = (tHTable*) malloc ( sizeof(tHTable) );
    htInit(ptrht);
    htInit(ptrlocalht);
    
    tKey klic = "a";
    tData data;
    data.pSymbolName = "_a";
    data.SymbolType = UNDEF;
    htInsert(ptrht, klic, data);
    
    klic = "b";
    data.pSymbolName = "_b";
    data.SymbolType = STRING;
    htInsert(ptrht, klic, data);
   
    klic = "a";
    data.pSymbolName = "_a";
    data.SymbolType = UNDEF;
    htInsert(ptrlocalht, klic, data);
    
    klic = "b";
    data.pSymbolName = "_b";
    data.SymbolType = STRING;
    htInsert(ptrlocalht, klic, data);
    
    
    char * exp;
    switch(StxExp(&exp)){
	  case RTN_OK:	_debug("Expression parser probehl v poradku");	
			break;
	  case RTN_SYNTAX:
			_error("nastala syntakticka chyba");
			break;
	  case RTN_SEMAN:
			_error("nastala semanticka chyba");
			break;
	  default:
			_error("nastala neocekavana chyba");
			break;
	  
    }
    _debug_printHT(ptrlocalht);
    _debug_instructions(&InstructionList);
    DisposeIList(&InstructionList);
    htClearAll(ptrht);
    htClearAll(ptrlocalht);
    
//     _debug_printAllocTable();
    _debug("expression parser vratil hodnotu: %s",exp);
    AllocClearMemmory();
    fclose(InputFile);
  return 0;
} 